import { MemoryManager } from "GameLoop/DecisionMaking/MemoryManager";
import { ABaseEntity } from "GameLoop/WorldState/EntityManager/Entitys/BaseEntity";
import { AllEntityTypes, ExucuteType, IEntity } from "GameLoop/WorldState/EntityManager/Entitys/Entity.interface";

 

 
/**
 * 房间位置拓展
 */
export default class EntityExtension extends Creep implements IEntity<CreepMemory & INoMemory> ,ICombat<IAttackTactic|IDefendTactic>
{
   public entityType(): ExucuteType {
      return "Creep"
   }
   initAttributes():void
   {
        MemoryManager.allocHeap(this.GUID());
        this.room.registerCreepPos(this);
   }
   public getEntityByID<T extends ABaseEntity<INoMemory>>(id: string): T 
   {
      return global.entityDB.getEntityByID<T>(id);         
   }
   public  getEntity<T extends keyof AllEntityTypes>(type: T, region: string=this.memory.OwnerRoom): AllEntityTypes[T] {
      return global.entityDB.getEntity(type,region);    
   }
   public getEntitys<T extends keyof AllEntityTypes>(type: T, region: string=this.memory.OwnerRoom): AllEntityTypes[T][] {
      return global.entityDB.getEntitys(type,region);    
   }
   removeEntityByID(id: string): boolean {
      return global.entityDB.removeEntityByID(id);
   }
   public getNodeMemory(): CreepMemory   {
      return this.memory as CreepMemory 
   }
   public getNodeHeap<T extends any=CreepHeap>(): T{
     
      return MemoryManager.getHeap(this.GUID());
   }
   
   public GUID()
   {
      return this.name
   }

   public getTactic<T extends IAttackTactic|IDefendTactic>():T
   {
      return this.memory.tactic as T
   }

   public setTactic(tatic:IAttackTactic|IDefendTactic):void
   {
      this.memory.tactic = tatic;
   }

   /**
   * 绑定的房间
   * @returns 
   */
   public  ownerRoom():Room
   {
      return Game.rooms[this.memory.OwnerRoom]
   }
   public clearAction():void
   {
      (global.GameLoop as any).workerManager.actionManager.clearAction(this.GUID());
   }
   public log(type:LogType,...arg:[]):void
   {
       //if(this.room.name == "E56S54")
         if(Memory.Debug['debugCreep']  )
         {
               if( Memory.Debug['debugCreep']==this.name)
               {
                  global.Log.Text(this.GUID(),`[${this.pos}]\t`+arg.join("\t"),type);
               }
               
               return 
         }
         else if(Memory.Debug['debugRole']  )
         {
            if( Memory.Debug['debugRole']==this.ActiveRole())
            {
               global.Log.Text(this.GUID(),`[${this.pos}]\t`+arg.join("\t"),type);
            }
               
               return 
         }
         global.Log.Text(this.GUID(),`[${this.pos}]\t`+arg.join("\t"),type);
   }
    
 }